package main.java.view;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

public class HandleView extends JPanel {
    
    //Path of each image of the handle
    private static String handleUpImage = "images/HandleUp.png";
    private static String handleDownImage = "images/HandleDown.png";
    
    //static final variables of view dimension to modify them easier
    private static final int SIZE1 = 200;
    
    private Image handleImage;
    private String position;
    
    /**
     * Constructor HandleView
     */
    public HandleView() {
        //Set to up
        this.handleImage = new ImageIcon(handleUpImage).getImage(); 
        this.position = "Up";
        
        //Initialize panel info
        Dimension size = new Dimension(handleImage.getWidth(null), handleImage.getHeight(null));
        this.setPreferredSize(size);
        this.setMinimumSize(size);
        this.setMaximumSize(size);
        this.setSize(size);
        this.setLayout(null);
    }

    /**
     * Switch the image depending on the position of the handle
     * @param position : position of the handle
     */
    public void switchImage() {
        switch (position) {
            //If up then set handleDownImage
            case "Up": 
                this.handleImage = new ImageIcon(handleDownImage).getImage();
                this.position = "Down";
                break;
            //If down then set handleUpImage
            case "Down": 
                this.handleImage = new ImageIcon(handleUpImage).getImage();
                this.position = "Up";
                break;
    
            default:
                break;
        }
        //repaint
        paintImmediately(0, 0, SIZE1, SIZE1); 
    }

    /**
     * Draw image
     */
    public void paintComponent(Graphics g) {
        g.drawImage(handleImage, 0, 0, null);
    }
}
